package com.itheima.exception;

import com.itheima.domain.Code;
import com.itheima.domain.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class ProjectExceptionAdvice {
   @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e){
        //将异常信息告诉用户
        e.printStackTrace();
        return new Result(Code.BUSINESS_EXCEPTION,e.getMessage());

    }
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e){
        //此处主要是java代码异常：空指针异常、算术异常、SQL异常...
        //这类异常信息应该保持到文件、redis、mysql等地方，然后通知运维人员和开发人员，给客户一个友好的提示信息。
        e.printStackTrace();
        return new Result(Code.OTHER_EXCEPTION,"服务器正在升级，稍等...");

    }
}
